package net.sky.oa.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 个人通讯录分组
 * MyGroup. @author hond
 */
@Entity
@Table(name = "MY_GROUP")//个人通讯分组表
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MyGroup implements Serializable {

	private static final long serialVersionUID = 5673991033245515351L;
	
	// Fields
	private Long id;
	private String name;   //分组名
	private Date createtime; 
	private SysEmployee empl;
	
	private Set<MyGroupEmpl> groupEmpl = new HashSet<MyGroupEmpl>(0);

	// Constructors

	/** default constructor */
	public MyGroup() {
	}

	/** minimal constructor */
	public MyGroup(Long id) {
		this.id = id;
	}
	
	@Id 
	@SequenceGenerator(name="SQ_MYGROUP_ID",sequenceName="SQ_MYGROUP_ID",allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SQ_MYGROUP_ID")
	@Column(name = "ID", unique = true, nullable = false)	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NAME", length = 20)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATETIME", length = 7)
	public Date getCreatetime() {
		return this.createtime;
	}
	
	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "USER_ID")
	public SysEmployee getEmpl() {
		return this.empl;
	}

	public void setEmpl(SysEmployee empl) {
		this.empl = empl;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "my_groupempl",joinColumns = { @JoinColumn(name = "group_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id", nullable = false, updatable = false) })
	public Set<MyGroupEmpl> getGroupEmpl() {
		return this.groupEmpl;
	}

	public void setGroupEmpl(Set<MyGroupEmpl> groupEmpl) {
		this.groupEmpl = groupEmpl;
	}

}